package com.humngyang.com.hmy.study.concurrency.myannoations.concurrencyTest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConcurrencySynchorized {
    private static Logger log = LoggerFactory.getLogger(ConcurrencySynchorized.class);
    //修饰同步代码块
    public void test1(){
        synchronized (this){
            for (int i = 0; i <10 ; i++) {
                log.info("test1 {}",i);
            }
        }
    }
    //同步方法
    public synchronized void test2(){
        for (int i = 0; i <10 ; i++) {
            log.info("test2 {}",i);
        }
    }
    //修饰一个类
    public void test3(){
        synchronized (ConcurrencySynchorized.class){
            for (int i = 0; i <10 ; i++) {
                log.info("test1 {}",i);
            }
        }
    }
    //修饰一个方法
    public static synchronized void test4(){
        for (int i = 0; i <10 ; i++) {
            log.info("test2 {}",i);
        }
    }

}
